#include <windows.h>	// for mutex handle
#include <stdio.h>		// for mutex handle

#include <time.h>

#ifndef _BufferManager
#define _BufferManager

struct Buffer {
	bool isReady;
	char *data;
	int count;

	Buffer *prev, *next;
};

class BufferManager {

public:
	long count;	// used to slow down data coming in too fast
	Buffer *head, *tail;

	// insure thread-safe
	HANDLE mutex;

	// Constructor
	BufferManager(HANDLE /*mutex*/);
	// Deconstructor
	~BufferManager();

	// free up all memory used by link list
	void clear();

	bool addBytes(char*, int);

	// if there is a '\n' in the buffer
	bool isReady();

	// returns a pointer to the current available string,
	// or NULL if none is available
	char* getNext();

	// check if two Buffers need to be combined to get a full string
	void merge(Buffer*);

	// removes current available string
	void pop();

	// display buffer link-list
	void dump();
};

#endif // _BufferManager